package com.hzy.admin.controller.base;

import java.util.List;
import java.util.Map;

import com.hzy.admin.framework.ApiResult;
import com.hzy.admin.framework.annotation.AdminAuthorization;
import com.hzy.admin.framework.controller.ApiBaseController;
import com.hzy.admin.models.vo.system.TableVo;
import com.hzy.admin.services.IMemberService;
import com.hzy.admin.repository.entity.Member;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 会员控制器
 *
 * @author hzy
 */
@Api(tags = "会员控制器")
@RestController
@RequestMapping("/admin/member")
@AdminAuthorization("60ae9382-31ab-4276-a379-d3876e9bb783")
public class MemberController extends ApiBaseController<IMemberService> {
    public MemberController(IMemberService service) {
        super(service);
    }

    /**
     * 查询列表
     *
     * @param page   页码
     * @param size   页数
     * @param search 查询
     * @return json
     */
    @ApiOperation("查询列表")
    @PostMapping("/findList/{size}/{page}")
    @ResponseBody
    public ApiResult<?> findList(@PathVariable Integer page, @PathVariable Integer size, @RequestBody Member search) {
        TableVo<Map<String, Object>> tableViewDto = this.service.findList(page, size, search);
        return this.resultOk(tableViewDto);
    }

    /**
     * 根据 id 查询表单信息
     *
     * @param id id
     * @return json
     */
    @ApiOperation("根据 id 查询表单信息")
    @GetMapping(value = {"/findForm/{id}", "/findForm"})
    @ResponseBody
    public ApiResult<?> findForm(@PathVariable(required = false) String id) {
        return this.resultOk(this.service.findForm(id));
    }

    /**
     * 保存数据
     *
     * @param form 要保存数据
     * @return json
     */
    @ApiOperation("保存数据")
    @PostMapping("/saveForm")
    @ResponseBody
    public ApiResult<?> saveForm(@ModelAttribute Member form,
                                 @RequestParam(name = "filePhoto", required = false) final MultipartFile filePhoto,
                                 @RequestParam(name = "files", required = false) final MultipartFile[] files) {
        return this.resultOk(this.service.saveForm(form, filePhoto, files));
    }

    /**
     * 删除
     *
     * @param ids id集合
     * @return json
     */
    @ApiOperation("删除")
    @PostMapping("/deleteList")
    @ResponseBody
    public ApiResult<?> deleteList(@RequestBody List<String> ids) {
        this.service.deleteList(ids);
        return this.resultOk();
    }
}
